package com.zpark;

import java.util.Scanner;

public class demo02 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入猴子总数");
        int n = scan.nextInt();
        System.out.println("请输入每一次要数到几");
        int m = scan.nextInt();
        int[] flag = new int[n];
        int index = -1, count, pNum = n;
// 只要存活的猴子大于一只，就持续进行
        while (pNum > 1) {
            count = 0;
            while (count != m) {
                index = (index + 1) % n;
                if (flag[index] == 0) {
                    count++;
                    if (count == m)
                        flag[index] = 1;
                }
            }
            pNum--;
        }
// 打印最后剩下的猴王
        for (int i = 0; i < n; i++) {
            if (flag[i] == 0)
                System.out.println("第" + (i + 1) + "只猴子成为猴王！");
        }
    }

}